<template>
  <view class="dashboard">
    <text class="title">控制台</text>
    <view class="stats">
      <view class="stat-card">
        <text class="value">{{animal}}</text>
        <text class="label">新增流浪动物</text>
      </view>
	  <view class="stat-card">
	    <text class="value">{{demand}}</text>
	    <text class="label">新增领养需求</text>
	  </view>
      <view class="stat-card">
        <text class="value">{{user}}</text>
        <text class="label">新增用户</text>
      </view>

    </view>
  </view>
</template>

<script setup>
	import {onShow} from '@dcloudio/uni-app'
import { ref } from 'vue';
	import {baseUrl} from '../static/js/common.js'
	let animal=ref(0)
	let demand=ref(0)
	let user=ref(0)
	onShow(()=>{
		let token=localStorage.getItem("admin-token")
		if(token==null){
			uni.navigateTo({
				url:'/pages/login/login'
			})
		}
		uni.request({
			url: baseUrl + '/user/getSystemInfo',
			header:{'Authorization':token},
			success: (res) => {
				let data=res.data.data
				animal.value=data.animalCount
				demand.value=data.postCount
				user.value=data.userCount
			}
		})
	})
</script>
<style scoped>
.dashboard {
  .title {
    font-size: 48rpx;
    color: #333;
    margin-bottom: 40rpx;
  }

  .stats {
    display: flex;
    gap: 30rpx;

    .stat-card {
      flex: 1;
      background: #fff;
      padding: 30rpx;
      border-radius: 12rpx;
      box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.1);

      .value {
        display: block;
        font-size: 48rpx;
        color: #42b983;
      }

      .label {
        color: #999;
        font-size: 28rpx;
      }
    }
  }
}
</style>